//
//  LGDeviceRecycleView.m
//  HeartDiseaseManage
//
//  Created by 1234 on 2025/2/27.
//  设备回收 -- 弹框

#import "LGDeviceRecycleView.h"
#import "LGCustomTextView.h"
#define lineHeight  viewPix(44)

@interface LGDeviceRecycleView()<LGBottomButtonDelegate,LGTextViewDelegate>
/**   */
@property (nonatomic , strong)UIView *baseView;
/**   */
@property (nonatomic , strong)UILabel *titleLabel;
/**   */
@property (nonatomic , strong)UILabel *nameLabel;

/**  设备编号 */
@property (nonatomic , strong)UIButton *numberTitle;
@property (nonatomic , strong)UILabel *numberLabel;

/**  设备状态 */
@property (nonatomic , strong)UIButton *statusTitle;
@property (nonatomic , strong)UIButton *storageBtn;
@property (nonatomic , strong)UIButton *giveButton;
@property (nonatomic , strong)UIButton *loseButton;

/**  入库仓库 */
@property (nonatomic , strong)UIButton *warehouseTitle;
@property (nonatomic , strong)UIView *warehouseView;
@property (nonatomic , strong)UILabel *warehouseLabel;

/**  押金状态 */
@property (nonatomic , strong)UIButton *cashTitle;
@property (nonatomic , strong)UIButton *paidButton;
@property (nonatomic , strong)UIButton *refundedBtn;

/**  备注 */
@property (nonatomic , strong)UIButton *remarkTitle;
@property (nonatomic , strong)LGCustomTextView *remarkTF;

/**   */
@property (nonatomic , strong)LGBottomButtonView *bottomView;

/**   */
@property (nonatomic , assign)CGFloat totalHeight;
/**   */
@property (nonatomic , assign)CGFloat warehouseH;
/**   */
@property (nonatomic , assign)CGFloat remarkHeight;
/**   */
@property (nonatomic , assign)CGFloat tempHeight;
/**   */
@property (nonatomic , copy)NSString *warehouseid;
/**   */
@property (nonatomic , assign)CGFloat keyboardH;
/**   */
@property (nonatomic , copy)NSString *deviceState;
/**   */
@property (nonatomic , copy)NSString *cashState;

@end

@implementation LGDeviceRecycleView

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        self.deviceState = @"";
        self.cashState = @"";
        self.remarkHeight = viewPix(70);
        [self createSubView];
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
    }
    return self;
}

-(void)setType:(NSString *)type{
    _type = type;
    if ([type isEqualToString:@"0"]) {
        //服务包
        self.remarkHeight = viewPix(70);
        self.remarkTitle.hidden = NO;
        self.remarkTF.hidden = NO;
        self.cashTitle.hidden = NO;
        self.paidButton.hidden = NO;
        self.refundedBtn.hidden = NO;
        self.giveButton.hidden = NO;
        self.tempHeight = viewPix(150)+lineHeight*2 + viewPix(12)*3 + viewPix(76)+bottomSafeBarHeight/4.0+viewPix(20);
        [self.loseButton mas_updateConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.giveButton.mas_right).offset(viewPix(8));
        }];
    }else{
        //商城 -- 不显示押金、备注
        self.remarkHeight = 0;
        self.remarkTitle.hidden = YES;
        self.remarkTF.hidden = YES;
        self.cashTitle.hidden = YES;
        self.paidButton.hidden = YES;
        self.refundedBtn.hidden = YES;
        self.giveButton.hidden = NO;
        self.tempHeight = viewPix(150)+lineHeight + viewPix(12)*2 + viewPix(76)+bottomSafeBarHeight/4.0+viewPix(20);
        [self.loseButton mas_updateConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.giveButton.mas_right).offset(-(Screen_W-viewPix(161))/3.0);
        }];
    }
}

-(void)setDataDic:(NSDictionary *)dataDic{
    _dataDic = dataDic;
    self.nameLabel.text = [NSString stringWithFormat:@"%@  %@",dataDic[@"patient"][@"realname"],dataDic[@"patient"][@"mobile"]];
    self.numberLabel.text = [self.type isEqualToString:@"0"] ? LGNSString(dataDic[@"equipment_sn"]):LGNSString(dataDic[@"goods_no"]);
    //入库仓库
    self.warehouseid = @"";
    NSString *warehouse = @"";
    if (dataDic[@"inventory"] && [dataDic[@"inventory"] isKindOfClass:[NSDictionary class]]) {
        self.warehouseid = LGNSString(dataDic[@"inventory"][@"id"]);
        warehouse = [LGNSString(dataDic[@"inventory"][@"title"]) isEmptyString]?@"":LGNSString(dataDic[@"inventory"][@"title"]);
    }
    self.warehouseLabel.text = warehouse;
    CGFloat warehouseH = [warehouse textHeightWithFont:LGFont(16) maxWidth:Screen_W-viewPix(180)]+viewPix(24);
    self.warehouseH = warehouseH>lineHeight?warehouseH:lineHeight;
    [self.warehouseView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.height.equalTo(@(self.warehouseH));
    }];

    self.totalHeight = self.tempHeight+self.warehouseH+self.remarkHeight;
    if ([self.type isEqualToString:@"0"] && [LGNSString(dataDic[@"order_id"]) isEqualToString:@"0"]) {
        //服务包 -- 没有付押金 -- 不显示押金状态
        self.cashTitle.hidden = YES;
        self.paidButton.hidden = YES;
        self.refundedBtn.hidden = YES;
        [self.remarkTitle mas_updateConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.cashTitle.mas_bottom).offset(-lineHeight);
        }];
        self.totalHeight -= lineHeight+viewPix(12);
    }
    
    self.baseView.frame = CGRectMake(0, Screen_H, Screen_W, self.totalHeight+viewPix(20));
    [UIView animateWithDuration:0.3 animations:^{
        self.baseView.frame = CGRectMake(0, Screen_H-self.totalHeight, Screen_W, self.totalHeight+viewPix(20));
    }];
}


-(void)keyboardWillShow:(NSNotification *)notification{
    NSInteger duration = [notification.userInfo[UIKeyboardAnimationDurationUserInfoKey] integerValue];
    CGRect keyboardFrame = [notification.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
    CGFloat height = keyboardFrame.size.height;
    self.keyboardH = height;
    height = height+kMaxY(self.remarkTF.frame);
    [UIView animateWithDuration:duration animations:^{
        self.baseView.frame = CGRectMake(0, Screen_H-height, Screen_W, self.baseView.bounds.size.height);
    }];
}

-(void)keyboardWillHide:(NSNotification *)notification{
    NSInteger duration = [notification.userInfo[UIKeyboardAnimationDurationUserInfoKey] integerValue];
    [UIView animateWithDuration:duration animations:^{
        self.baseView.frame = CGRectMake(0, Screen_H-self.baseView.bounds.size.height+viewPix(20), Screen_W, self.baseView.bounds.size.height);
    } completion:^(BOOL finished) {
       
    }];
}

//选择设备状态
-(void)selectTypeAction:(UIButton *)sender{
    if (sender.selected == YES) return;
    sender.selected = YES;
    [sender addBorder:@"#5E8EF5" lineWidth:1 cornerRidus:3];
    if (sender == self.storageBtn) {
        //已入库
        self.deviceState = [self.type isEqualToString:@"0"]? @"putstorage":@"1";
        self.giveButton.selected = [self.type isEqualToString:@"0"]?NO:YES;
        self.loseButton.selected = NO;
        [self.giveButton addBorder:@"#D9D9D9" lineWidth:1 cornerRidus:3];
        [self.loseButton addBorder:@"#D9D9D9" lineWidth:1 cornerRidus:3];
        if ([self.type isEqualToString:@"0"]) {
            //服务包 -- 已入库 -- 入口仓库显示 -- 押金状态：已付押金显示，没付押金不显示
            self.remarkHeight = viewPix(70);
            self.remarkTitle.hidden = NO;
            self.remarkTF.hidden = NO;
            if ([LGNSString(self.dataDic[@"order_id"]) isEqualToString:@"0"]) {
                self.cashTitle.hidden = YES;
                self.paidButton.hidden = YES;
                self.refundedBtn.hidden = YES;
                [self.remarkTitle mas_updateConstraints:^(MASConstraintMaker *make) {
                    make.top.equalTo(self.cashTitle.mas_bottom).offset(-lineHeight);
                }];
                
            }else{
                self.cashTitle.hidden = NO;
                self.paidButton.hidden = NO;
                self.refundedBtn.hidden = NO;
                [self.remarkTitle mas_updateConstraints:^(MASConstraintMaker *make) {
                    make.top.equalTo(self.cashTitle.mas_bottom).offset(viewPix(12));
                }];
            }
            
            self.warehouseTitle.hidden = NO;
            self.warehouseView.hidden = NO;
            self.warehouseLabel.hidden = NO;
            self.giveButton.hidden = NO;
            self.tempHeight = viewPix(150)+lineHeight*2 + viewPix(12)*3 + viewPix(76)+bottomSafeBarHeight/4.0+viewPix(20);
            [self.loseButton mas_updateConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(self.giveButton.mas_right).offset(viewPix(8));
            }];
            [self.warehouseTitle mas_updateConstraints:^(MASConstraintMaker *make) {
                make.top.equalTo(self.statusTitle.mas_bottom).offset(viewPix(12));
            }];
            [self.warehouseView mas_updateConstraints:^(MASConstraintMaker *make) {
                make.height.equalTo(@(self.warehouseH));
            }];
        }else{
            //商城 -- 不显示押金、备注
            self.remarkHeight = 0;
            self.remarkTitle.hidden = YES;
            self.remarkTF.hidden = YES;
            self.cashTitle.hidden = YES;
            self.paidButton.hidden = YES;
            self.refundedBtn.hidden = YES;
            self.giveButton.hidden = NO;
            self.warehouseTitle.hidden = NO;
            self.warehouseView.hidden = NO;
            self.warehouseLabel.hidden = NO;
            self.tempHeight = viewPix(150)+lineHeight + viewPix(12)*2 + viewPix(76)+bottomSafeBarHeight/4.0+viewPix(20);
            [self.loseButton mas_updateConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(self.giveButton.mas_right).offset(-(Screen_W-viewPix(161))/3.0);
            }];
        }
        
    }else if (sender == self.giveButton) {
        //续包赠送
        self.deviceState = @"give";
        self.storageBtn.selected = NO;
        self.loseButton.selected = NO;
        [self.storageBtn addBorder:@"#D9D9D9" lineWidth:1 cornerRidus:3];
        [self.loseButton addBorder:@"#D9D9D9" lineWidth:1 cornerRidus:3];
        if ([self.type isEqualToString:@"0"]) {
            //服务包 -- 续包赠送 -- 不显示入库仓库
            self.remarkHeight = viewPix(70);
            self.remarkTitle.hidden = NO;
            self.remarkTF.hidden = NO;
            self.warehouseTitle.hidden = YES;
            self.warehouseView.hidden = YES;
            self.warehouseLabel.hidden = YES;
            self.giveButton.hidden = NO;
            if ([LGNSString(self.dataDic[@"order_id"]) isEqualToString:@"0"]) {
                self.cashTitle.hidden = YES;
                self.paidButton.hidden = YES;
                self.refundedBtn.hidden = YES;
                [self.remarkTitle mas_updateConstraints:^(MASConstraintMaker *make) {
                    make.top.equalTo(self.cashTitle.mas_bottom).offset(-lineHeight);
                }];
                
            }else{
                self.cashTitle.hidden = NO;
                self.paidButton.hidden = NO;
                self.refundedBtn.hidden = NO;
                [self.remarkTitle mas_updateConstraints:^(MASConstraintMaker *make) {
                    make.top.equalTo(self.cashTitle.mas_bottom).offset(viewPix(12));
                }];
            }
            self.tempHeight = viewPix(150)+lineHeight*2 + viewPix(12)*3 + viewPix(76)+bottomSafeBarHeight/4.0+viewPix(20);
            [self.loseButton mas_updateConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(self.giveButton.mas_right).offset(viewPix(8));
            }];
            [self.warehouseTitle mas_updateConstraints:^(MASConstraintMaker *make) {
                make.top.equalTo(self.statusTitle.mas_bottom);
            }];
            [self.warehouseView mas_updateConstraints:^(MASConstraintMaker *make) {
                make.height.equalTo(@(0));
            }];
            
            
        }
        
    }else{
        //回收失败
        self.deviceState = [self.type isEqualToString:@"0"]?@"lose":@"0";
        self.storageBtn.selected = NO;
        self.giveButton.selected = [self.type isEqualToString:@"0"]?NO:YES;
        [self.storageBtn addBorder:@"#D9D9D9" lineWidth:1 cornerRidus:3];
        [self.giveButton addBorder:@"#D9D9D9" lineWidth:1 cornerRidus:3];
        
        if ([self.type isEqualToString:@"0"]) {
            //服务包 -- 回收失败 -- 不显示入口仓库 、 押金
            self.remarkHeight = viewPix(70);
            self.remarkTitle.hidden = NO;
            self.remarkTF.hidden = NO;
            self.cashTitle.hidden = YES;
            self.paidButton.hidden = YES;
            self.refundedBtn.hidden = YES;
            self.warehouseTitle.hidden = YES;
            self.warehouseView.hidden = YES;
            self.warehouseLabel.hidden = YES;
            self.giveButton.hidden = NO;
            self.tempHeight = viewPix(150)+lineHeight*2 + viewPix(12)*3 + viewPix(76)+bottomSafeBarHeight/4.0+viewPix(20);
            [self.loseButton mas_updateConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(self.giveButton.mas_right).offset(viewPix(8));
            }];
            [self.warehouseTitle mas_updateConstraints:^(MASConstraintMaker *make) {
                make.top.equalTo(self.statusTitle.mas_bottom);
            }];
            [self.warehouseView mas_updateConstraints:^(MASConstraintMaker *make) {
                make.height.equalTo(@(0));
            }];
            [self.remarkTitle mas_updateConstraints:^(MASConstraintMaker *make) {
                make.top.equalTo(self.cashTitle.mas_bottom).offset(-lineHeight);
            }];
        }else{
            //商城 -- 回收失败 -- 不显示入库仓库、押金、备注
            self.remarkHeight = 0;
            self.remarkTitle.hidden = YES;
            self.remarkTF.hidden = YES;
            self.cashTitle.hidden = YES;
            self.paidButton.hidden = YES;
            self.refundedBtn.hidden = YES;
            self.warehouseTitle.hidden = YES;
            self.warehouseView.hidden = YES;
            self.warehouseLabel.hidden = YES;
            self.giveButton.hidden = NO;
            self.tempHeight = viewPix(150)+lineHeight + viewPix(12)*2 + viewPix(76)+bottomSafeBarHeight/4.0+viewPix(20);
            [self.loseButton mas_updateConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(self.giveButton.mas_right).offset(-(Screen_W-viewPix(161))/3.0);
            }];
            
        }
        
    }
}

//选择押金状态
-(void)selectCashAction:(UIButton *)sender{
    if (sender.selected == YES) return;
    sender.selected = YES;
    [sender addBorder:@"#5E8EF5" lineWidth:1 cornerRidus:3];
    if (sender == self.paidButton) {
        //已支付
        self.cashState = @"0";
        self.refundedBtn.selected = NO;
        [self.refundedBtn addBorder:@"#D9D9D9" lineWidth:1 cornerRidus:3];
        
    }else{
        //已退款
        self.cashState = @"1";
        self.paidButton.selected = NO;
        [self.paidButton addBorder:@"#D9D9D9" lineWidth:1 cornerRidus:3];
    }
}


-(void)textViewHeightChanged:(CGFloat)height{
    self.remarkHeight = height<viewPix(70)?viewPix(70):height;
    CGFloat remarkH = self.remarkTF.bounds.size.height;
    if (self.remarkHeight != remarkH) {
        [self.remarkTF mas_updateConstraints:^(MASConstraintMaker *make) {
            make.height.equalTo(@(self.remarkHeight));
        }];
        self.totalHeight = self.tempHeight+self.warehouseH+self.remarkHeight;
        CGFloat top = kMinY(self.remarkTF.frame);
        self.baseView.frame = CGRectMake(0, Screen_H-(top+self.remarkHeight+self.keyboardH+viewPix(10)), Screen_W, self.totalHeight+viewPix(20));
    }
}

-(void)bottomButtonTouchedWithIndex:(NSInteger)index{
    if (index == 2) {
        NSMutableDictionary *saveDic = [NSMutableDictionary dictionary];
        
        if (self.deviceState.length == 0) {
            [TooltipView showMessage:@"请选择设备状态" offset:0];
            return;
        }
        if ([self.type isEqualToString:@"0"]) {
            //服务包 -- 设备回收
            if (self.cashState.length == 0 && ![LGNSString(self.dataDic[@"order_id"]) isEqualToString:@"0"] && self.loseButton.selected == NO) {
                [TooltipView showMessage:@"请选择押金状态" offset:0];
                return;
            }
            [saveDic setValue:LGNSString(self.dataDic[@"id"]) forKey:@"receipt_id"];
            [saveDic setValue:self.deviceState forKey:@"type"];
            [saveDic setValue:self.cashState forKey:@"deposit_refund"];
            [saveDic setValue:self.remarkTF.content forKey:@"remarks"];
            
        }else{
            //商城 -- 设备回收
            [saveDic setValue:LGNSString(self.dataDic[@"order_id"]) forKey:@"order_id"];
            [saveDic setValue:self.deviceState forKey:@"is_back"];
        }
        
        [saveDic setValue:self.warehouseid forKey:@"inventory_inid"];
        NSString *action = [self.type isEqualToString:@"0"]?@"/doctor/equipment.equipment/putStorage":@"/doctor/equipment.equipment/orderRecover";
        [RequestUtil withPOST:action parameters:saveDic withSign:YES success:^(NSInteger code, NSString *message, id returnData) {
            if (code == 200) {
                NSString *notifName = [self.type isEqualToString:@"0"]?@"DeviceRefreshService":@"DeviceRefreshShope";
                [[NSNotificationCenter defaultCenter] postNotificationName:notifName object:nil];
                [UIView animateWithDuration:0.3 animations:^{
                    self.baseView.frame = CGRectMake(0, Screen_H, Screen_W, self.totalHeight+viewPix(20));
                } completion:^(BOOL finished) {
                    [self removeFromSuperview];
                }];
            }else{
                [TooltipView showMessage:message offset:0];
            }
        } error:^(NSError *error) {
            [TooltipView showMessage:@"保存失败，请重试" offset:0];
        }];
        
    }else{
        [UIView animateWithDuration:0.3 animations:^{
            self.baseView.frame = CGRectMake(0, Screen_H, Screen_W, self.totalHeight+viewPix(20));
        } completion:^(BOOL finished) {
            [self removeFromSuperview];
        }];
    }
}


#pragma mark
#pragma mark ====> 创建控件
-(void)createSubView{
    [self addSubview:self.baseView];
    [self.baseView addSubview:self.titleLabel];
    [self.baseView addSubview:self.nameLabel];
    [self.baseView addSubview:self.numberTitle];
    [self.baseView addSubview:self.numberLabel];
    
    [self.baseView addSubview:self.statusTitle];
    [self.baseView addSubview:self.storageBtn];
    [self.baseView addSubview:self.giveButton];
    [self.baseView addSubview:self.loseButton];
    //入口仓库
    [self.baseView addSubview:self.warehouseTitle];
    [self.baseView addSubview:self.warehouseView];
    [self.baseView addSubview:self.warehouseLabel];
    
    [self.baseView addSubview:self.cashTitle];
    [self.baseView addSubview:self.paidButton];
    [self.baseView addSubview:self.refundedBtn];

    [self.baseView addSubview:self.remarkTitle];
    [self.baseView addSubview:self.remarkTF];
    
    [self.baseView addSubview:self.bottomView];
  
    [self.numberTitle mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.nameLabel.mas_bottom).offset(viewPix(5));
        make.left.equalTo(self.baseView).offset(viewPix(18));
        make.width.equalTo(@(viewPix(80)));
        make.height.equalTo(@(viewPix(25)));
    }];
    
    [self.numberLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.numberTitle.mas_right).offset(viewPix(35));
        make.right.equalTo(self.baseView).offset(-viewPix(12));
        make.centerY.equalTo(self.numberTitle);
    }];
    
    [self.statusTitle mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.numberTitle.mas_bottom).offset(viewPix(12));
        make.left.width.equalTo(self.numberTitle);
        make.height.equalTo(@(lineHeight));
    }];
    
    [self.storageBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.statusTitle.mas_right).offset(viewPix(35));
        make.centerY.equalTo(self.statusTitle);
        make.width.equalTo(@((Screen_W-viewPix(161))/3.0));
        make.height.equalTo(@(lineHeight));
    }];
    
    [self.giveButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.storageBtn.mas_right).offset(viewPix(8));
        make.width.height.centerY.equalTo(self.storageBtn);
    }];
    
    [self.loseButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.giveButton.mas_right).offset(viewPix(8));
        make.width.height.centerY.equalTo(self.storageBtn);
    }];
    
    [self.warehouseTitle mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.statusTitle.mas_bottom).offset(viewPix(12));
        make.left.width.equalTo(self.statusTitle);
        make.height.equalTo(@(lineHeight));
    }];
    
    [self.warehouseView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self.numberLabel);
        make.top.equalTo(self.warehouseTitle);
        make.height.equalTo(@(lineHeight));
    }];
    
    [self.warehouseLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.warehouseView).offset(viewPix(12));
        make.left.equalTo(self.warehouseView).offset(viewPix(16));
        make.right.equalTo(self.warehouseView).offset(-viewPix(12));
    }];
    
    [self.cashTitle mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.warehouseView.mas_bottom).offset(viewPix(12));
        make.left.width.equalTo(self.statusTitle);
        make.height.equalTo(@(lineHeight));
    }];
    
    [self.paidButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.numberLabel);
        make.centerY.equalTo(self.cashTitle);
        make.width.equalTo(@((Screen_W-viewPix(153))/2.0));
        make.height.equalTo(@(lineHeight));
    }];
    
    [self.refundedBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.paidButton.mas_right).offset(viewPix(8));
        make.width.height.centerY.equalTo(self.paidButton);
    }];
    
    [self.remarkTitle mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.cashTitle.mas_bottom).offset(viewPix(12));
        make.left.width.equalTo(self.statusTitle);
        make.height.equalTo(@(lineHeight));
    }];
    
    [self.remarkTF mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self.numberLabel);
        make.top.equalTo(self.remarkTitle);
        make.height.equalTo(@(viewPix(70)));
    }];
    
    [self.bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.baseView).offset(-viewPix(10));
        make.right.equalTo(self.baseView).offset(viewPix(10));
        make.bottom.equalTo(self.baseView);
        make.height.equalTo(@(viewPix(76)+bottomSafeBarHeight/4.0+viewPix(20)));
    }];
}

-(UIView *)baseView{
    if(!_baseView){
        _baseView = [[UIView alloc] initWithFrame:CGRectMake(0, Screen_H, Screen_W, viewPix(300))];
        _baseView.backgroundColor = [UIColor whiteColor];
        _baseView.cornerRidus = 7;
    }
    return _baseView;
}

-(UILabel *)titleLabel{
    if(!_titleLabel){
        _titleLabel = [UILabel lableWithText:@"设备回收" colorString:@"#000000" textFont:LGFontWeight(18, UIFontWeightSemibold) textAlignment:NSTextAlignmentCenter lines:1];
        _titleLabel.frame = CGRectMake(0, viewPix(20), Screen_W, viewPix(25));
    }
    return _titleLabel;
}

-(UILabel *)nameLabel{
    if(!_nameLabel){
        _nameLabel = [UILabel lableWithText:@"" colorString:@"#282828" textFont:LGFontWeight(16, UIFontWeightMedium) textAlignment:NSTextAlignmentLeft lines:1];
        _nameLabel.frame = CGRectMake(viewPix(18), viewPix(56), Screen_W-viewPix(30), viewPix(22));
    }
    return _nameLabel;
}


-(UIButton *)numberTitle{
    if(!_numberTitle){
        _numberTitle = [UIButton buttonWithTitle:@"  设备编号" titleFont:LGFont(16) textColor:@"#282828" imageName:@""];
        _numberTitle.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
        _numberTitle.userInteractionEnabled = NO;
    }
    return _numberTitle;
}

-(UILabel *)numberLabel{
    if(!_numberLabel){
        _numberLabel = [UILabel lableWithText:@"" colorString:@"#282828" textFont:LGFontWeight(16, UIFontWeightMedium) textAlignment:NSTextAlignmentLeft lines:1];
    }
    return _numberLabel;
}

-(UIButton *)statusTitle{
    if(!_statusTitle){
        _statusTitle = [UIButton buttonWithTitle:@"设备状态" titleFont:LGFont(16) textColor:@"#282828" imageName:@"必选项2"];
        _statusTitle.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
        _statusTitle.userInteractionEnabled = NO;
    }
    return _statusTitle;
}

-(UIButton *)storageBtn{
    if(!_storageBtn){
        _storageBtn = [UIButton buttonWithTitle:@"已入库" titleFont:LGFont(16) normalColor:@"#282828" selectColor:@"#5E8EF5"];
        _storageBtn.cornerRidus = 3;
        [_storageBtn setBackgroundColor:@"#FFFFFF" selectColor:@"#E5F1FF"];
        [_storageBtn addBorder:@"#D9D9D9" lineWidth:1 cornerRidus:3];
        [_storageBtn addTarget:self action:@selector(selectTypeAction:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _storageBtn;
}

-(UIButton *)giveButton{
    if(!_giveButton){
        _giveButton = [UIButton buttonWithTitle:@"续包赠送" titleFont:LGFont(16) normalColor:@"#282828" selectColor:@"#5E8EF5"];
        _giveButton.cornerRidus = 3;
        [_giveButton setBackgroundColor:@"#FFFFFF" selectColor:@"#E5F1FF"];
        [_giveButton addBorder:@"#D9D9D9" lineWidth:1 cornerRidus:3];
        [_giveButton addTarget:self action:@selector(selectTypeAction:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _giveButton;
}

-(UIButton *)loseButton{
    if(!_loseButton){
        _loseButton = [UIButton buttonWithTitle:@"回收失败" titleFont:LGFont(16) normalColor:@"#282828" selectColor:@"#5E8EF5"];
        _loseButton.cornerRidus = 3;
        [_loseButton setBackgroundColor:@"#FFFFFF" selectColor:@"#E5F1FF"];
        [_loseButton addBorder:@"#D9D9D9" lineWidth:1 cornerRidus:3];
        [_loseButton addTarget:self action:@selector(selectTypeAction:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _loseButton;
}

-(UIButton *)warehouseTitle{
    if(!_warehouseTitle){
        _warehouseTitle = [UIButton buttonWithTitle:@"入库仓库" titleFont:LGFont(16) textColor:@"#282828" imageName:@"必选项2"];
        _warehouseTitle.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
        _warehouseTitle.userInteractionEnabled = NO;
    }
    return _warehouseTitle;
}

-(UIView *)warehouseView{
    if(!_warehouseView){
        _warehouseView = [[UIView alloc]init];
        _warehouseView.backgroundColor = [UIColor colorWithString:@"#F5F7F9"];
        [_warehouseView addBorder:@"#D9D9D9" lineWidth:1 cornerRidus:3];
    }
    return _warehouseView;
}

-(UILabel *)warehouseLabel{
    if(!_warehouseLabel){
        _warehouseLabel = [UILabel lableWithText:@"" colorString:@"#282828" textFont:LGFont(16) textAlignment:NSTextAlignmentLeft lines:0];
    }
    return _warehouseLabel;
}

-(UIButton *)cashTitle{
    if(!_cashTitle){
        _cashTitle = [UIButton buttonWithTitle:@"押金状态" titleFont:LGFont(16) textColor:@"#282828" imageName:@"必选项2"];
        _cashTitle.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
        _cashTitle.userInteractionEnabled = NO;
    }
    return _cashTitle;
}

-(UIButton *)paidButton{
    if(!_paidButton){
        _paidButton = [UIButton buttonWithTitle:@"已支付" titleFont:LGFont(16) normalColor:@"#282828" selectColor:@"#5E8EF5"];
        _paidButton.cornerRidus = 3;
        [_paidButton setBackgroundColor:@"#FFFFFF" selectColor:@"#E5F1FF"];
        [_paidButton addBorder:@"#D9D9D9" lineWidth:1 cornerRidus:3];
        [_paidButton addTarget:self action:@selector(selectCashAction:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _paidButton;
}

-(UIButton *)refundedBtn{
    if(!_refundedBtn){
        _refundedBtn = [UIButton buttonWithTitle:@"已退款" titleFont:LGFont(16) normalColor:@"#282828" selectColor:@"#5E8EF5"];
        _refundedBtn.cornerRidus = 3;
        [_refundedBtn setBackgroundColor:@"#FFFFFF" selectColor:@"#E5F1FF"];
        [_refundedBtn addBorder:@"#D9D9D9" lineWidth:1 cornerRidus:3];
        [_refundedBtn addTarget:self action:@selector(selectCashAction:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _refundedBtn;
}


-(UIButton *)remarkTitle{
    if(!_remarkTitle){
        _remarkTitle = [UIButton buttonWithTitle:@"  备注" titleFont:LGFont(16) textColor:@"#282828" imageName:@""];
        _remarkTitle.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
        _remarkTitle.userInteractionEnabled = NO;
    }
    return _remarkTitle;
}

-(LGCustomTextView *)remarkTF{
    if(!_remarkTF){
        _remarkTF = [LGCustomTextView textViewWithPlaceHolder:@"请输入" textColor:@"#282828" textFont:LGFont(16) textAlignment:NSTextAlignmentLeft keyboard:UIKeyboardTypeDefault];
        [_remarkTF addBorder:@"#D9D9D9" lineWidth:1 cornerRidus:3];
        _remarkTF.backgroundColor = [UIColor colorWithString:@"#FFFFFF"];
        _remarkTF.placeHolderColor = @"#909399";
        _remarkTF.placeHolderFont = LGFont(16);
        _remarkTF.maxCount = 100;
        _remarkTF.customDelegate = self;
    }
    return _remarkTF;
}


-(LGBottomButtonView *)bottomView{
    if(!_bottomView){
        _bottomView = [[LGBottomButtonView alloc] initWithItemArray:@[@{@"title":@"取消" , @"color":@"#4C87FD" ,@"type":@"bolder"},@{@"title":@"确定" , @"color":@"#4C87FD" ,@"type":@"back"}] frame:CGRectMake(0, self.baseView.bounds.size.height-bottomSafeBarHeight/4.0-viewPix(76), Screen_W+viewPix(20), viewPix(76))];
        [_bottomView setShadoWithColor:@"#D9D9D9" offset:CGSizeMake(0, -1) opacity:0.5 radius:0];
        _bottomView.backgroundColor = [UIColor whiteColor];
        _bottomView.radius = viewPix(23);
        _bottomView.delegate = self;
    }
    return _bottomView;
}


@end
